#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "QtLocationPlugin/QGCMapEngine.h"
#include <QtPlugin>
#include "QGCMapEngineManager.h"
#include <QQmlContext>
#include "RouteService.h"

int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
    QGuiApplication app(argc, argv);
    Q_IMPORT_PLUGIN(QGeoServiceProviderFactoryQGC)

    QQmlApplicationEngine engine;
    getQGCMapEngine()->init();
    QGCMapEngineManager* _mgr = new QGCMapEngineManager();
    
    // 创建路线服务实例
    RouteService* routeService = new RouteService();
    
    engine.addImportPath("qrc:/");
    engine.rootContext()->setContextProperty("mapEngineManager", _mgr);
    engine.rootContext()->setContextProperty("routeService", routeService);
    
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}
